<?php

function getMicrotime()
{
    list($usec, $sec) = explode(' ', microtime());
    return ((float) $usec + (float) $sec);
}
$path = './';
foreach (range(0, 2) as $num) {
    $filename = $path . 'f' . $num . '.md';
    if (!is_file($filename)) {
        $res = exec('dd if=/dev/zero of=' . $filename . ' bs=1M count=80');
        echo '创建文件' . $filename . "s \n";
        var_dump($res);
    }
}

go(function () {
    $path = './';
    $start_time = getMicrotime();
    echo '协程start at ' . date('Y-m-d H:i:s') . " \n";


    foreach (range(0, 2) as $num) {
        $filename = 'f_' . $num;


        go(function () use ($filename, $path) {
            $start = getMicrotime();
            $$filename = file_get_contents($path . 'f0.md');
            echo "\n" . $$filename . "\n\t读取[" . $filename . ']文件用了' . (getMicrotime() - $start) . "s \n";
        });

        $org = $path . 'f' . $num . '.md';
        if (is_file($org)) {
            // unlink($org);
        }
    }

    echo '协程end at ' . date('Y-m-d H:i:s') . " \n";
    echo 'It takes ' . (getMicrotime() - $start_time) . "s !!! \n";
});
